/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       caravan.h

	$Header: $

	$NoKeywords: $

 ************************************************************************/

#ifndef CARAVAN_H_INCLUDED
#define CARAVAN_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <iosfwd>
#include <string>

#include "counted_ptr.h"
#include "creature_array.h"
#include "town_ptr.h"

class t_adventure_object;

// -------------------------------------------------------------
// Caravan
// This represents an in-transit caravan. Caravans are started 
// using the caravan window, and arrive some days later at 
// a town. In-between leaving and arriving, they do not appear on
// the map at all.
// -------------------------------------------------------------
class t_caravan : public t_counted_object, public t_creature_array
{
	public:
		enum { k_daily_movement = 3000 }; // Movement per day of a caravan

		explicit t_caravan( t_adventure_map * map, int arrival_day = -1, t_adventure_object * origin = NULL, t_town_ptr destination = NULL, int owner = -1);

		bool						add_caravan_to_army( t_creature_array & destination );	// Move the caravan into the given army
		int							get_arrival_day() const;		// Day the caravan arrives
		static t_uint16				get_caravan_version();			// Get # to (eventually) pass into all read calls
		t_town_ptr					get_destination() const;		// Destination town
		virtual t_adventure_map *	get_map() const;				// Map the caravan is on (or not on, I guess)
		std::string					get_origin_name() const;				// Origin town or dwelling
		int							get_owner_number() const;		// Owner ID
		bool						has_arrived() const;			// Has the caravan arrived?
		void						increment_arrival_day();        // In cases where it couldn't arrive today, make it arrive tomorrow...
		void						process_new_day();
		bool						read( std::streambuf & stream, t_uint16 caravan_version );
		bool						write( std::streambuf & stream ) const;

	private:
		int						m_arrival_day; // Day the caravan arrives
		t_town_ptr				m_destination; // Destination town
		t_adventure_map *		m_map;		   // Map the caravan is on (or not on, I guess)
		std::string				m_origin_name; // Name of origin town or dwelling or whatever
		int						m_owner;	   // Owner number
};

// -------------------------------------------------------------
// Inlines...
// -------------------------------------------------------------
// -------------------------------------------------------------
// -------------------------------------------------------------
inline int t_caravan::get_arrival_day() const
{
	return m_arrival_day;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
inline t_town_ptr t_caravan::get_destination() const
{
	return m_destination;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
inline std::string t_caravan::get_origin_name() const
{
	return m_origin_name;
}

// -------------------------------------------------------------
// -------------------------------------------------------------
inline int t_caravan::get_owner_number() const
{
	return m_owner;
}


// -------------------------------------------------------------
// -------------------------------------------------------------
inline void t_caravan::increment_arrival_day()
{
	m_arrival_day++;
}

#endif // CARAVAN_H_INCLUDED
